//
//  MineTitleTableViewCell.swift
//  Gaoloumi
//
//  Created by Jasper on 3/6/16.
//  Copyright © 2016 Jasper. All rights reserved.
//

import UIKit
import AVOSCloud

class MineTitleCell: UITableViewCell {
    
    @IBOutlet weak var headerImageView: UIImageView!
    @IBOutlet weak var lineHeight: NSLayoutConstraint!
    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var fatieNumLabel: UILabel!
    @IBOutlet weak var huitieNumLabel: UILabel!
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        lineHeight.constant = 0.25
        //        refreshView()
        headerImageView.layer.cornerRadius = 5
        headerImageView.layer.masksToBounds = true
    }
    
    func refreshView() {
        let user = AVUser.current()
        if user != nil {
            nameLabel.text = user.username
            let imgFile = user.object(forKey: "avatar") as? AVFile
            
            if imgFile?.url != nil {
                headerImageView?.kf.setImage(with: URL(string: (imgFile?.url)!)!,
                                             placeholder: DataCenter.sharedInstance.placeholderImage,
                                             options: nil,
                                             progressBlock: { receivedSize, totalSize in
                                                
                    },
                                             completionHandler: { image, error, cacheType, imageURL in
                                                
                })
                
                
            } else {
                headerImageView.image = UIImage(named: "defaultUser")
            }
            
            let sendCount = user.object(forKey: kUserKeySendCount) as? Int
            if sendCount != nil {
                fatieNumLabel.text = "\(sendCount!)"
            } else {
                fatieNumLabel.text = "0"
            }
            
            let replyCount = user.object(forKey: kUserKeyReplyCount) as? Int
            if replyCount != nil {
                huitieNumLabel.text = "\(replyCount!)"
            } else {
                huitieNumLabel.text = "0"
            }
            
        } else {
            headerImageView.image = UIImage(named: "defaultUser")
            nameLabel.text = "请登录"
            fatieNumLabel.text = "0"
            huitieNumLabel.text = "0"
        }
        
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
    }
    
}
